/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject_sem2;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author ZER0
 */
public class Employee extends javax.swing.JFrame {
    private static final long serialVersionUID = 1L;

    Employee_sever s = new Employee_sever();
    VotesSent_Sever a = new VotesSent_Sever();

    public JInternalFrame getItnfEmployee() {
        return itnfEmployee;
    }
    

    /**
     * Creates new form Employee
     */
    public Employee() throws SQLException {
        initComponents();
        a.AddDatainJComboBox("Departments", cbxDepartmentID);
        tfEmployeeID.setText(a.CreateID("Employee", "EL"));
        tfEmployeeID.setEditable(false);
        s.ShowTable("EmployeeID", "EmployeeName", "EmployeeAddress", "PhoneNumber", "DepartmentID", "Employee", tbIfEmployee,"All");

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        itnfEmployee = new javax.swing.JInternalFrame();
        jpIfEmployee = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbIfEmployee = new javax.swing.JTable();
        jpUInformation = new javax.swing.JPanel();
        lbEmployeeID = new javax.swing.JLabel();
        lbEmployeeName = new javax.swing.JLabel();
        tfEmployeeID = new javax.swing.JTextField();
        tfEmployeeName = new javax.swing.JTextField();
        lbPhoneNumber = new javax.swing.JLabel();
        txtfPhoneNumber = new javax.swing.JTextField();
        btEditE = new javax.swing.JButton();
        btExitE = new javax.swing.JButton();
        btAddE = new javax.swing.JButton();
        btResetE = new javax.swing.JButton();
        btDeleteE = new javax.swing.JButton();
        lbEAddress = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtaEAddress = new javax.swing.JTextArea();
        lbDepartmentID = new javax.swing.JLabel();
        cbxDepartmentID = new javax.swing.JComboBox();
        cbxShowE = new javax.swing.JComboBox();
        lbShowD = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        itnfEmployee.setClosable(true);
        itnfEmployee.setVisible(true);

        jpIfEmployee.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1), "Information employee", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        tbIfEmployee.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "EmployeeID", "Employee Name", "Employee Address", "Phone Number", "DepartmentID"
            }
        ));
        tbIfEmployee.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbIfEmployeeMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbIfEmployee);

        jpUInformation.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Update Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        lbEmployeeID.setText("EmployeeID:");

        lbEmployeeName.setText("Employee Name:");

        lbPhoneNumber.setText("Phone Number:");

        btEditE.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/1484902.png"))); // NOI18N
        btEditE.setText("Edit");
        btEditE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditEActionPerformed(evt);
            }
        });

        btExitE.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/Exit.png"))); // NOI18N
        btExitE.setText("Exit");
        btExitE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExitEActionPerformed(evt);
            }
        });

        btAddE.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/Open-Folder-Add-icon.png"))); // NOI18N
        btAddE.setText("ADD");
        btAddE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddEActionPerformed(evt);
            }
        });

        btResetE.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/icon_reset.png"))); // NOI18N
        btResetE.setText("Reset");
        btResetE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btResetEActionPerformed(evt);
            }
        });

        btDeleteE.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/trash-can-delete.png"))); // NOI18N
        btDeleteE.setText("Delete");
        btDeleteE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDeleteEActionPerformed(evt);
            }
        });

        lbEAddress.setText("Employee Address:");

        txtaEAddress.setColumns(20);
        txtaEAddress.setRows(5);
        jScrollPane2.setViewportView(txtaEAddress);

        lbDepartmentID.setText("DepartmentID:");

        javax.swing.GroupLayout jpUInformationLayout = new javax.swing.GroupLayout(jpUInformation);
        jpUInformation.setLayout(jpUInformationLayout);
        jpUInformationLayout.setHorizontalGroup(
            jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpUInformationLayout.createSequentialGroup()
                .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpUInformationLayout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbEmployeeID)
                            .addComponent(lbEmployeeName)
                            .addComponent(lbPhoneNumber))
                        .addGap(18, 18, 18)
                        .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(tfEmployeeID, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                                .addComponent(tfEmployeeName))
                            .addComponent(txtfPhoneNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpUInformationLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btAddE, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpUInformationLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(btEditE, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btDeleteE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btResetE, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btExitE, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpUInformationLayout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbDepartmentID)
                            .addComponent(lbEAddress))
                        .addGap(18, 18, 18)
                        .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
                            .addComponent(cbxDepartmentID, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(41, Short.MAX_VALUE))
        );
        jpUInformationLayout.setVerticalGroup(
            jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpUInformationLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpUInformationLayout.createSequentialGroup()
                        .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfEmployeeID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbEmployeeID)
                            .addComponent(lbEAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfEmployeeName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbEmployeeName)))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtfPhoneNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPhoneNumber)
                    .addComponent(lbDepartmentID)
                    .addComponent(cbxDepartmentID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(jpUInformationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btAddE, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btEditE, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btDeleteE, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btResetE, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btExitE, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(83, 83, 83))
        );

        cbxShowE.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Business", "Delivery", "Accounting" }));
        cbxShowE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbxShowEActionPerformed(evt);
            }
        });

        lbShowD.setText("Show by department:");

        javax.swing.GroupLayout jpIfEmployeeLayout = new javax.swing.GroupLayout(jpIfEmployee);
        jpIfEmployee.setLayout(jpIfEmployeeLayout);
        jpIfEmployeeLayout.setHorizontalGroup(
            jpIfEmployeeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpIfEmployeeLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lbShowD)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbxShowE, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(44, 44, 44))
            .addComponent(jScrollPane1)
            .addComponent(jpUInformation, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jpIfEmployeeLayout.setVerticalGroup(
            jpIfEmployeeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpIfEmployeeLayout.createSequentialGroup()
                .addGroup(jpIfEmployeeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbxShowE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbShowD))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpUInformation, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout itnfEmployeeLayout = new javax.swing.GroupLayout(itnfEmployee.getContentPane());
        itnfEmployee.getContentPane().setLayout(itnfEmployeeLayout);
        itnfEmployeeLayout.setHorizontalGroup(
            itnfEmployeeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpIfEmployee, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        itnfEmployeeLayout.setVerticalGroup(
            itnfEmployeeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpIfEmployee, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfEmployee)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfEmployee, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tbIfEmployeeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbIfEmployeeMouseClicked
        // TODO add your handling code here:
        tbIfEmployee.getSelectedRow();
        tfEmployeeID.setText((String) tbIfEmployee.getValueAt(tbIfEmployee.getSelectedRow(), 0));
        tfEmployeeName.setText((String) tbIfEmployee.getValueAt(tbIfEmployee.getSelectedRow(), 1));
        txtaEAddress.setText((String) tbIfEmployee.getValueAt(tbIfEmployee.getSelectedRow(), 2));
        txtfPhoneNumber.setText(Integer.toString((int) tbIfEmployee.getValueAt(tbIfEmployee.getSelectedRow(), 3)));
    }//GEN-LAST:event_tbIfEmployeeMouseClicked

    private void btEditEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditEActionPerformed
        // TODO add your handling code here:
        int result = JOptionPane.showConfirmDialog(this, "Do you want to edit the information?", "Information", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
            if ((s.UpdatePrice(tfEmployeeID.getText(), tfEmployeeName.getText(), txtaEAddress.getText(), Integer.parseInt(txtfPhoneNumber.getText()),(String) cbxDepartmentID.getSelectedItem(), "Employee", "EmployeeID", "EmployeeName", "EmployeeAddress", "PhoneNumber", "DepartmentID")) != true) {
                s.ShowTable("EmployeeID", "EmployeeName", "EmployeeAddress", "PhoneNumber", "DepartmentID", "Employee", tbIfEmployee, "All");
            } else {
                JOptionPane.showMessageDialog(rootPane, "Data error");
            }
        }
    }//GEN-LAST:event_btEditEActionPerformed

    private void btExitEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExitEActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_btExitEActionPerformed

    private void btAddEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddEActionPerformed
        try {
            // TODO add your handling code here:
            if (s.CheckIDPrice(tfEmployeeID.getText(), "Employee") != -1) {
                JOptionPane.showMessageDialog(this, "No add,ID already exists,You can to edit the information?");
            } else {
                if ((s.InsertPrice(tfEmployeeID.getText(), tfEmployeeName.getText(), txtaEAddress.getText(), Integer.parseInt(txtfPhoneNumber.getText()),(String) cbxDepartmentID.getSelectedItem(), "Employee", "EmployeeID", "EmployeeName", "EmployeeAddress", "PhoneNumber", "DepartmentID")) == true) {
                    s.ShowTable("EmployeeID", "EmployeeName", "EmployeeAddress", "PhoneNumber", "DepartmentID", "Employee", tbIfEmployee, "All");
                } else {
                    JOptionPane.showMessageDialog(rootPane, "Error data enter");
                }
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Employee.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Employee.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btAddEActionPerformed

    private void btResetEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResetEActionPerformed
        // TODO add your handling code here:
        s.ShowTable("EmployeeID", "EmployeeName", "EmployeeAddress", "PhoneNumber", "DepartmentID", "Employee", tbIfEmployee, "All");
        tfEmployeeID.setText(a.CreateID("Employee", "EL"));
        tfEmployeeName.setText(null);
        txtfPhoneNumber.setText(null);
        cbxDepartmentID.setSelectedItem(1);
        txtaEAddress.setText(null);
    }//GEN-LAST:event_btResetEActionPerformed

    private void btDeleteEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDeleteEActionPerformed
        // TODO add your handling code here:
        int result = JOptionPane.showConfirmDialog(this, "Do you want to delete the information?", "Information", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
            s.Remove("Prices_by_regions", tfEmployeeID.getText(), "RegionsID");
            s.ShowTable("EmployeeID", "EmployeeName", "EmployeeAddress", "PhoneNumber", "DepartmentID", "Employee", tbIfEmployee, "All");
        }
    }//GEN-LAST:event_btDeleteEActionPerformed

    private void cbxShowEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxShowEActionPerformed
        // TODO add your handling code here:
        String m = (String) cbxShowE.getSelectedItem();
        s.ShowTable("EmployeeID", "EmployeeName", "EmployeeAddress", "PhoneNumber", "DepartmentID", "Employee", tbIfEmployee, m);
    }//GEN-LAST:event_cbxShowEActionPerformed

    /**
     * @param args the command line arguments
     */
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAddE;
    private javax.swing.JButton btDeleteE;
    private javax.swing.JButton btEditE;
    private javax.swing.JButton btExitE;
    private javax.swing.JButton btResetE;
    private javax.swing.JComboBox cbxDepartmentID;
    private javax.swing.JComboBox cbxShowE;
    private javax.swing.JInternalFrame itnfEmployee;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel jpIfEmployee;
    private javax.swing.JPanel jpUInformation;
    private javax.swing.JLabel lbDepartmentID;
    private javax.swing.JLabel lbEAddress;
    private javax.swing.JLabel lbEmployeeID;
    private javax.swing.JLabel lbEmployeeName;
    private javax.swing.JLabel lbPhoneNumber;
    private javax.swing.JLabel lbShowD;
    private javax.swing.JTable tbIfEmployee;
    private javax.swing.JTextField tfEmployeeID;
    private javax.swing.JTextField tfEmployeeName;
    private javax.swing.JTextArea txtaEAddress;
    private javax.swing.JTextField txtfPhoneNumber;
    // End of variables declaration//GEN-END:variables
}
